package com.gxuwz.lhleavesys.service.impl;

import com.gxuwz.lhleavesys.dao.TeacherDao;
import com.gxuwz.lhleavesys.entity.Teacher;
import com.gxuwz.lhleavesys.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherDao teacherDao;

    @Override
    public boolean checkUser(String name, String password) throws SQLException {
        Teacher teacher = new Teacher();
        teacher.setName(name == null ? "0" : name);
        teacher.setPassword(password == null ? "0" : password);
        List<Teacher> list = teacherDao.query(teacher);

        return !list.isEmpty();
    }

    /**
     * 查询 BY ID
     * 
     * @param
     * @return
     */
    @Override
    public Teacher getTeacherByInstID(String instID) {
        return teacherDao.findByInstID(instID);
    }

    /**
     * 查询所有
     * 
     * @return
     */
    @Override
    public List<Teacher> getAllorOne(String id, String name) {
        return teacherDao.findAllorOne(id, name);
    }

    /**
     * 新增
     * 
     * @param
     * @return
     */
    @Override
    public boolean addTeacher(Teacher teacher) {
        return teacherDao.insert(teacher);
    }

    /**
     * 修改
     * 
     * @param
     * @return
     */
    @Override
    public boolean updateTeacher(Teacher teacher, String id) {
        return teacherDao.update(teacher, id);
    }

    /**
     * 删除 BY ID
     * 
     * @param id
     * @return
     */
    @Override
    public boolean deleteTeacher(String id) {
        return teacherDao.delete(id);
    }

    /**
     * 查询 BY 名称
     * 
     * @param name
     * @return
     */
    @Override
    public Teacher findTeacherByName(String name) {
        return teacherDao.findInstructorByinstName(name);
    }

}
